import React, { Component } from 'react'



export default function isLogin(Com) {
  return class hightcom extends Component {
    getCookie(key) {
      var name = key + "=";
      var decodedCookie = decodeURIComponent(document.cookie);
      var ca = decodedCookie.split(';');
      for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) === ' ') {
          c = c.substring(1);
        }
        if (c.indexOf(name) === 0) {
          return c.substring(name.length, c.length);
        }
      }
      return "";
    }
    componentDidMount() {
      let uid = this.getCookie('token')
      if (!uid) {
        this.$message.warning('请先登录')
        this.props.history.push('/login')
        return
      }
    }
    render() {
      return <Com {...this.props} />
    }

  }
}